define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form, undefined) {
    if(Config.product_id == '' || Config.product_id == null){
        Config.product_id = 0;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionproductmaterialc/index/?product_id=' + Config.product_id,
                    add_url: 'feditionproductmaterialc/add',
                    edit_url: 'feditionproductmaterialc/edit',
                    del_url: 'feditionproductmaterialc/del',
                    multi_url: 'feditionproductmaterialc/multi',
                    import_url: 'feditionproductmaterialc/import',
                    table: 'fedition_orderquantity',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'quantity',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'timedate', title: __('Timedate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM"},
                        {field: 'admin_name', title: __('店铺管理者'), operate: false},
                        {field: 'accounturl', title: __('Accounturl'),visible: false,addClass: "selectpage", extend: "data-source='feditionaccounturl/index' data-field='name'"},
                        {field: 'accounturl_name', title: __('Accounturl'), operate: false},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'quantity', title: __('该变体商品数'), operate: 'LIKE'},
                        {field: 'material', title: __('采购成本'), operate: 'BETWEEN'},
                        {field: 'sku', title: __('SKU'), operate: 'LIKE'},
                        {field: 'variant_id', title: __('变体id'), operate: 'LIKE'},
                        {field: 'variant_title', title: __('变体名称'), operate: 'LIKE'},
                    ]
                ]
            });

            // 当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                $("#zorders").text(data.Statistics.zorders);
                $("#zmaterial").text(data.Statistics.zmaterial);
                $("#zcount").text(data.Statistics.zcount);
                $("#zcountnot").text(data.Statistics.zcountnot);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});